package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

//    @Insert("insert into sky_take_out.orders(number, status, user_id, address_book_id, order_time, checkout_time, pay_method, " +
//            "pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, " +
//            "estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status) VALUES " +
//            "(#{number},#{status},#{userId},#{addressBookId},#{orderTime},#{checkoutTime},#{payMethod},#{payStatus},#{amount}," +
//            "#{remark},#{phone},#{address},#{userName},#{consignee},#{cancelReason},#{rejectionReason},#{cancelTime},#{estimatedDeliveryTime}" +
//            ",#{deliveryStatus},#{deliveryTime},#{packAmount},#{tablewareNumber},#{tablewareStatus})")
    void submit(Orders orders);


    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Select("select * from sky_take_out.orders where status=#{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime time);

    @Select("select * from sky_take_out.orders")
    List<Orders> selectall();

    @Select("select * from sky_take_out.orders where id=#{id}")
    Orders selectById(Long id);

    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

//    @Select("select sum(sky_take_out.orders.amount) from sky_take_out.orders where sky_take_out.orders.order_time between #{begintime} and #{endtime} " +
//            "and sky_take_out.orders.status=5")
    /*
        查询每天的营销额
     */
    Double sumByTime(LocalDateTime begintime, LocalDateTime endtime);

    /*
        查询每天的订单总数和有效订单数
     */
//    @Select("select count(*) from sky_take_out.orders where order_time between #{begintime} and #{endtime} and status=#{status}")
    Long sumeveryday(LocalDateTime begintime, LocalDateTime endtime,Integer status);

    /*
        查询给的日期内总订单数和总有效单数
     */

    Integer count(LocalDateTime endtime,Integer status);

    List<GoodsSalesDTO> top10(LocalDateTime begintime,LocalDateTime endtime);

    Double sumByMap(Map map);

    Integer countByMap(Map map);


}
